package kr.co.kiso.usr.bd.ma.service;

import java.util.List;
import java.util.Map;

import kr.co.kiso.usr.bd.ma.dao.BDMADao;
import kr.co.kiso.usr.bd.ma.vo.BDMAVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BDMAService {
	@Autowired
	public BDMADao dao;
	
	
	public List bdma010Q(BDMAVo vo) throws Exception {
		return dao.bdma010Q(vo);
	}
	
	public List bdma011Q(BDMAVo vo) throws Exception {
		return dao.bdma011Q(vo);
	}
	
	
	public int bdma010Q_cnt(BDMAVo vo) throws Exception {
		return dao.bdma010Q_cnt(vo);
	}
	
	public int bdma020Q() throws Exception {
		return dao.bdma020Q();
	}
	
	@Transactional(propagation=Propagation.REQUIRED)
	public int bdma020T(BDMAVo vo) throws Exception {
		//자료저장
		vo.setBrd_seq_no(dao.bdma020Q());
		
		dao.bdma020T(vo);
		
		if(vo.getFileList()!=null && vo.getFileList().size()>0){
			for(int i = 0; i < vo.getFileList().size(); i++){
				vo.setFile_seq_no(dao.bdma021Q(vo));
				Map map = (Map) vo.getFileList().get(i);
				vo.setM_file_nm((String)map.get("p_file_nm"));
				vo.setV_file_nm((String)map.get("file_nm"));
				vo.setFile_size((String)map.get("file_size"));
				
				dao.bdma021T(vo);
			}
		}
		//파일저장
//		dao.bdma021T(vo);
		return (int) vo.getBrd_seq_no();
	}
	
	public void bdma021T(BDMAVo vo) throws Exception {
		//자료저장
		vo.setBrd_seq_no(dao.bdma020Q());
	}
	
	//삭제할 물리 파일 정보 가져오기
	public List bdma040Q(BDMAVo vo) throws Exception {

		return dao.bdma040Q(vo);
	}
	
	/**
	 * 파일 삭제
	 * @param vo
	 * @return
	 * @throws Exception
	 */
	public int bdma041t(BDMAVo vo) throws Exception {

		return dao.bdma041t(vo);
	}
	/**
	 * comment 삭제
	 * @param vo
	 * @return
	 * @throws Exception
	 */
	public int bdma042t(BDMAVo vo) throws Exception {

		return dao.bdma042t(vo);
	}
	
	/** 게시판 삭제
	 * @param vo
	 * @return
	 * @throws Exception
	 */
	public int bdma043t(BDMAVo vo) throws Exception {

		return dao.bdma043t(vo);
	}
	
	
	public Map bdma050Q(BDMAVo vo) throws Exception {

		return dao.bdma050Q(vo);
	}
	
	public List bdma051Q(BDMAVo vo) throws Exception {

		return dao.bdma051Q(vo);
	}

	public List bdma052Q(BDMAVo vo) throws Exception {

		return dao.bdma052Q(vo);
	}
	
	
	public Map bdma053Q(BDMAVo vo) throws Exception {

		return dao.bdma053Q(vo);
	}
	
	public Map bdma054Q(BDMAVo vo) throws Exception {

		return dao.bdma054Q(vo);
	}
	
	
	
	
	public void bdma060T(BDMAVo vo) throws Exception {
		//자료수정
		dao.bdma060T(vo);
		
		for(int i = 0; i < vo.getFileList().size(); i++){
			vo.setFile_seq_no(dao.bdma021Q(vo));
			Map map = (Map) vo.getFileList().get(i);
			vo.setM_file_nm((String)map.get("p_file_nm"));
			vo.setV_file_nm((String)map.get("file_nm"));
			dao.bdma021T(vo);
		}
	}
	
	public void bdma061T(BDMAVo vo) throws Exception {
		//사용자 자료수정
		dao.bdma061T(vo);
	}
	
	public List bdma061Q(BDMAVo vo) throws Exception {
		//자료수정
		return dao.bdma061Q(vo);
		
	}
	
	public int bdma062Q(BDMAVo vo) throws Exception {
		//자료수정
		return dao.bdma062Q(vo);
		
	}
	
	public void bdma070T(BDMAVo vo) throws Exception {
		//자료수정
		dao.bdma070T(vo);
		
	}
	
	public void bdma071T(BDMAVo vo) throws Exception {
		//자료수정
		dao.bdma071T(vo);
		
	}
	
	public Map bdma071Q(BDMAVo vo) throws Exception {
		//자료수정
		return dao.bdma071Q(vo);
	}
	
	
	
	public int bdma080T(BDMAVo vo) throws Exception {
		//자료수정
		return dao.bdma080T(vo);
		
	}
	
	public int bdma090T(BDMAVo vo) throws Exception {
		//자료 숨김처리 기능
		return dao.bdma090T(vo);
		
	}
	
	
}
